import {Component, EventEmitter, Input, Output} from '@angular/core';
import {Helper} from "../../common/Helper";
import {UserProvider} from "../../providers/user/user";

@Component({
  selector: 'g-bank-card',
  templateUrl: 'g-bank-card.html'
})
export class GBankCardComponent {

  @Input() card: any = {}
  @Input() readOnly: boolean = false
  @Output() delete = new EventEmitter()

  constructor(private user: UserProvider,
              private helper: Helper) {

  }

  unbind() {
    this.helper.alert({
      title: '是否解绑该银行卡？',
      buttons: [
        {
          text: '取消',
          cssClass: 'g-alert-cancel',
          role: 'cancel'
        },{
          text: '确认',
          handler: () => {
            this.user.removeBankCard({
              data:{
                id: this.card.id
              },
              success:()=>{
                this.delete.emit()
              }
            })
          }
        }
      ]
    })
  }

}
